package com.wanmait.meteor.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.wanmait.meteor.pojo.Meetinfo;
import com.wanmait.meteor.pojo.Userinfo;
import com.wanmait.meteor.service.ConfigService;
import com.wanmait.meteor.service.UserInfoService;
import com.wanmait.meteor.util.IgnoreToken;
import com.wanmait.meteor.util.JWTUtils;
import com.wanmait.meteor.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
public class UserInfoController {

    @Resource
    private UserInfoService userInfoService;

    @Resource
    private ConfigService configService;
    //陳 用户登录
    @IgnoreToken
    @PostMapping("login")
    public Result login(@RequestBody Userinfo userinfo){

        Userinfo loginUserinfo=userInfoService.login(userinfo);
        System.out.println(loginUserinfo);

        if(loginUserinfo==null){
            return Result.error("登录失败，用户名或者密码错误");
        }
        //创建token
        String token = JWTUtils.createToken(loginUserinfo);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("token",token);
        jsonObject.put("loginUserinfo",loginUserinfo);
        return Result.success(jsonObject);
    }
    //wf
    //条件查询  通过二级会议类型和会议名关键字查询 并分页
    @IgnoreToken
    @PostMapping("manage/selectUserinfoList")
    public Result selectList(Integer pageNum, @RequestBody Userinfo userinfo) {
        int pageSize = configService.selectPageSize();
        PageInfo<Userinfo> pageInfo = userInfoService.selectList(userinfo, pageNum, pageSize);
        return Result.success(pageInfo);

    }
    //wf 通过用户id删除用户
    @IgnoreToken
    @GetMapping("manage/delUserinfo")
    public Result delUserinfo(Integer id){
        userInfoService.delUserinfo(id);
        return Result.success();
    }
    //wf 通过用户id查找详细信息
    @IgnoreToken
    @GetMapping("manage/selectAUser")
    public Result selectAUser(Integer id){
        Userinfo userinfo= userInfoService.selectAUser(id);
        return Result.success(userinfo);
    }

    //金
    @PostMapping("userinfo/changeUserData")
    public Result changeUserData(){
        return null;
    }


}
